public class BinarySearch {

    public final static int[] arr = new int[] { -1, 0, 3, 5, 9, 12 };
    public final static int target = 12;

    public static void main(String[] args) {
        System.out.println(binarySearch());
    }

    public static int binarySearch() {
        int left = 0, right = arr.length - 1;
        while (left <= right) {
            int mid = (right - left) / 2 + left;
            int num = arr[mid];
            if (num == target) {
                return mid;
            } else if (num > target) {
                right = mid - 1;
            } else {
                left = mid + 1;
            }
        }
        return -1;
    }
}